#!/usr/bin/python

import subprocess

rfile = lambda n: "files/fortnow{}.txt".format(n)

results = []
for r1 in range(1, 61):
    f1 = rfile(r1)
    for r2 in range(r1 + 1, 61):
        f2 = rfile(r2)
        command = "java TfIdfViewer {} {}".format(f1, f2)
        out = subprocess.check_output(command, shell=True)
        num = float(out)
        print("{} {} {}".format(f1, f2, num))
        results.append(num)

print(sum(results) / len(results))
